package com.cainezhu.coolwind.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class Utils {

	public static final String USER = "userInfo";
	public static final boolean DEBUG = true;
	
	public static Object getSession(String key){
		Map session = ActionContext.getContext().getSession();
		return session.get(key);
	}
	
	public static void SetSession(String key,Object obj){
		Map session = ActionContext.getContext().getSession();
		session.put(key,obj);
	}
	
	public static void removeSession(String key){
		Map session = ActionContext.getContext().getSession();
		session.remove(key);
	}
	
	public static String dateFormatToString(Date date){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}
	
	public static Date stringFormateToDate(String date) throws ParseException{
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.parse(date);
	}
	
	public static String getNow(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date());
	}
	
	public static void console(String tag,String msg){
	   	if(DEBUG){
	   		System.out.println(getNow()+"  " + tag + "  " + msg);
	   	}
	}
	
    public static void console(String tag,String msg,boolean debug){
		if(debug){
			System.out.println(getNow()+"  " + tag + "  " + msg);
		}else{
			console(tag,msg);
		}
	}
    
    public static void console(String msg){
	   	if(DEBUG){
	   		System.out.println(getNow()+"  " + msg);
	   	}
	}
	
    public static void console(String msg,boolean debug){
		if(debug){
			System.out.println(getNow()+"  " + msg);
		}else{
			console(msg);
		}
	}
}
